/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.bionic.commands.user;

import com.bionic.commands.common.ICommand;
import com.bionic.dao.UserDAO;
import com.bionic.entity.Users;
import com.bionic.manager.Config;
import java.io.IOException;
import java.util.Enumeration;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import sun.misc.CharacterEncoder;


/**
 *
 * @author Obuhov D.G.
 */
public class CUserUpdateComfirm implements ICommand {

    @Override
    public String execute(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String page = null;
        
        UserDAO userDAO = new UserDAO();
        HttpSession session = request.getSession();
        
        Enumeration e = session.getAttributeNames();
        while (e.hasMoreElements()) {
        String name = (String) e.nextElement();
        System.out.println("L+ session "+name + ": " + session.getAttribute(name));
        }
       
        
        Users user = (Users) session.getAttribute("currentUser");
        
       
        if (user != null) {
            Integer rowUpdate;
          
             
            user.setFirstName((String) request.getParameter("userFirstName"));
            user.setLastName((String) request.getParameter("userLastName"));
            user.setPhone((String) request.getParameter("userPhone"));
            user.setEmail((String) request.getParameter("userEmail"));
            
            System.out.println("L+ user "+user);
            rowUpdate = userDAO.update(user);
            
            request.setAttribute("userBean", user);
            request.setAttribute("update_confirm","YES");
            
            page = Config.getInstance().getProperty(Config.USER_EDIT);
            
        } else {
            page = Config.getInstance().getProperty(Config.ERROR);
        }

        return page;
    }
}
